<?php
namespace app\admin\logic;

use app\admin\code\AdminCode;
use app\admin\model\AdminModel;
use app\admin\model\RoleModel;
use app\admin\validate\LoginValidate;
use think\Session;

class LoginLogic extends BaseLogic
{
    public function login(){
        $validate = new LoginValidate(new AdminModel());
        if($validate->validate($this->_param,__FUNCTION__) === false){
            $this->result = false;
            $this->err = $validate->getError();
            return false;
        }
        $adminInfo = $validate->get_db_data();
        unset($adminInfo['salt']);
        $role_model = new RoleModel();
        $auth = $role_model->findData(['id'=>$adminInfo['role_id']],'rule');
        $auth = explode(',',$auth['rule']);
        Session::set('admin.id',$adminInfo['id']);
        Session::set('admin.user_name',$adminInfo['user_name']);
        Session::set('admin.rule',$auth);
        $this->result = true;
        return true;
    }
}
